package cc.comac.mom.datahandlers.third.outsource;

import cc.comac.mom.bean.third.outsource.EquipPowerDepartMentOutSourceBean;
import cc.comac.mom.dao.entity.EquipRepairDao;
import cc.comac.mom.util.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

import java.nio.charset.StandardCharsets;

/**
 * 与设备动力部门的委外维修接口
 */
@Component
public class EquipPowerDepartMentOutSource {

    @Autowired
    private EquipRepairDao equipRepairDao;

    public ResultBean sendOutSourceData(Long id){
        ResultBean result =new ResultBean();
        //发送数据
        EquipPowerDepartMentOutSourceBean info=equipRepairDao.selectRepairInfoById(id);
        RestTemplate restTemplate = new RestTemplate();
        restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
        //设置请求头(注意会产生中文乱码)
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.MULTIPART_FORM_DATA);
        MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
        HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(
                map, headers);
        //发送请求，设置请求返回数据格式为String
        ResponseEntity<ResultBean> responseEntity = restTemplate.postForEntity("http:xxx.xx", info, ResultBean.class);
        return result;
    }
}
